var app = getApp();

Page({
  data: {
    getmsg: "发送验证码",
    yz: !1,
    codeValue: ''
  },
  onLoad: function(t) {
    var a = this;
    a.setData({
      platform: wx.getStorageSync("platform")
    }), app.util.request({
      url: "entry/wxapp/attachurl",
      cachetime: "0",
      success: function(t) {
        console.log(t), wx.setStorageSync("url", t.data), a.setData({
          url: t.data
        });
      }
    }), app.util.request({
      url: "entry/wxapp/GetSystem",
      cachetime: "0",
      success: function(t) {
        console.log(t), wx.setStorageSync("platform", t.data), wx.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#ffffff'
        }), wx.setNavigationBarTitle({
          title: t.data.pt_name
        }), a.setData({
          platform: t.data,
          color: t.data.color,
          name: t.data.pt_name
        });
      }
    });
  },
  name: function(t) {
    this.setData({
      user_name: t.detail.value
    });
  },
  phone: function(t) {
    this.setData({
      phone: t.detail.value
    });
  },
  sendmessg: function(t) {
    var a = this;
    console.log(a.data);
    var e = a.data.phone;
    if ("" == e || null == e) wx.showToast({
      title: "请输入手机号",
      icon: "",
      image: "",
      duration: 2e3,
      mask: !0,
      success: function(t) {},
      fail: function(t) {},
      complete: function(t) {}
    });
    else {
      for (var o = "", n = 0; n < 6; n++) o += Math.floor(10 * Math.random());
      console.log(o), app.util.request({
        url: "entry/wxapp/sms2",
        cachetime: "0",
        data: {
          code: o,
          tel: e,
          type: 2
        },
        success: function(t) {
          console.log(t);
        }
      }), a.setData({
        num: o
      });
      var s = 59,
        l = setInterval(function() {
          a.setData({
            getmsg: s + "s后重新发送",
            send: !0
          }), --s <= 0 && (clearInterval(l), a.setData({
            getmsg: "发送验证码",
            send: !1,
            num: 0
          }));
        }, 1e3);
    }
  },
  verification_code: function(t) {
    var a = t.detail.value,
      e = this.data.num;
    this.setData({
      codeValue: a
    })
    console.log(this.data.codeValue);
    console.log(this.data.num);
    // 6 == a.length && (a != e ? (wx.showModal({
    //   title: "",
    //   content: "验证码输入错误"
    // })) : this.setData({
    //   yz: !0
    // }));
  },
  getPhoneNumber: function(t) {
    var a = this;
    console.log(app), console.log(t), app.util.request({
      url: "entry/wxapp/jiemi",
      cachetime: "0",
      data: {
        sessionKey: app.getSK,
        iv: t.detail.iv,
        data: t.detail.encryptedData
      },
      success: function(t) {
        console.log("这是解密手机号"), console.log(t), a.setData({
          phone: t.data.phoneNumber
        });
      }
    });
  },
  confirm: function(t) {
    var a = this,
      e = a.data.user_name,
      o = a.data.phone,
      n = a.data.platform,
      num = a.data.num,
      code = a.data.codeValue,
      s = wx.getStorageSync("userInfo").id,
      l = "";
      console.log(a.data.num);

      if ("" == o || null == o) l = "请输入您的手机号";
      else if (num != code) {
      l = "验证码输入错误";
    }
    "" != l ? wx.showModal({
      content: l
    }) : app.util.request({
      url: "entry/wxapp/RenewUser",
      cachetime: "0",
      data: {
        tel: o,
        zs_name: e,
        user_id: s
      },
      success: function(t) {
        console.log("保存信息"), console.log(t), 1 == t.data && (wx.showToast({
          title: "提交成功"
        }), setTimeout(function() {
          wx.navigateBack({
            delta: 1
          });
        }, 1500));
      }
    });
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {}
});